﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace Quản_Lý_Thư_Viện
{
    class PhieunhapsachDataAccess
    {
        private DataProvider _provider = new DataProvider();
        public PhieunhapsachDataAccess()
        {
            _provider.connect();
        }
        public void insertphieunhapsach(PhieunhapsachInfo info)
        {
            string ngaynhap = info.Ngnhap.Value.Month + "/" + info.Ngnhap.Value.Day + "/" + info.Ngnhap.Value.Year;
            string insertCommand = "insert into dbo.PHIEUNHAPSACH values('" + info.Mapns + "','" + ngaynhap + "','" + info.Tongsoluong + "','" + info.Trigiapns + "')";
            _provider.executeNonQuery(insertCommand);
        }
        public void deletephieunhapsach(PhieunhapsachInfo info)
        {
            string deleteCommand = "Delete from dbo.PHIEUNHAPSACH where MAPNS = '" + info.Mapns + "'";
            _provider.executeNonQuery(deleteCommand);
        }
        public void updatephieunhapsach(PhieunhapsachInfo info)
        {
            string ngaynhap = info.Ngnhap.Value.Month + "/" + info.Ngnhap.Value.Day + "/" + info.Ngnhap.Value.Year;
            string updateCommand = "Update dbo.PHIEUNHAPSACH set NGNHAP = '" + ngaynhap
                + "',TONGSOLUONG = '"+info.Tongsoluong
                +"',TRIGIAPNS= '"+info.Trigiapns+"' where MAPNS = '"+info.Mapns+"'";
            _provider.executeNonQuery(updateCommand);
        }
        public DataTable laydspns()
        {
            return _provider.GetData("select * from dbo.PHIEUNHAPSACH order by MAPNS desc");
        }
        public DataTable timpns()
        {
            return _provider.GetData("select * from PHIEUNHAPSACH where MAPNS like '" + frmNhapKho.timpns + "%'");
        }
    }
}
